import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../components/Index.vue'
import Searched from '../components/main/searchedbooks.vue'
import BookDetails from '../components/book/BookDetails.vue'
import login from '../components/login.vue'
import center from '../components/center'
import OnlineBook from '../components/book/onlineRead.vue'
import Payment from '../components/payment/paymen2.vue'

import Home from '../components/Home.vue'
import User from '../components/user/user.vue'
import Book from '../components/books/Book.vue'
import Examine from '../components/books/examine.vue'
import Report from '../components/books/Report.vue'
import UserCounts from '../components/counts/userCounts.vue'
import BookCounts from '../components/counts/bookCounts.vue'

// const originalPush = VueRouter.prototype.push

// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }


Vue.use(VueRouter)
const routes = [
  {path: '/', redirect: '/index'},
  {path: '/index', component: Index, redirect: '/searched',children: [
    {path: '/bookdetails', name:'bookdetails',component: BookDetails},
    {path: '/searched', name: 'searched', component: Searched},
    {path: '/onlineRead', component: OnlineBook}
  ]},
  {path: '/login', component: login },
  {path:'/center',component: center},
  {path: '/home', component: Home, redirect:'/user',
    children:[
      //用户管理
      {path: '/user', component: User},
      //书籍列表
      {path: '/book', component: Book},
      //上传书籍审核
      {path: '/examine', component: Examine},
      //举报书籍受理
      {path: '/report', component: Report},
      //网站用户统计
      {path: '/userCounts', component: UserCounts},
      //网站书籍统计
      {path: '/bookCounts', component: BookCounts},
  ]},
  {path: '/payment', name:'payment', component: Payment}
]

const router = new VueRouter({
  mode: 'history',
  routes
})


export default router
